﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Text;
using Util;
public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Loadservices();
            Loadnotice();
            //Loadinfor();
            Loadnews();
           // Loadgroup();
            Loadparty();
            Loadlink();
           
        }
    }

    private void Loadlink()
    {
        var list = new BllLink().GetList(c => true, true, c => c.sort, 1, 7);
        StringBuilder sb = new StringBuilder();
        foreach (var item in list)
        {
            string name = item.name;
            sb.Append(string.Format(@"<a href='{0}'>
                    <img src='{1}' /></a> "
                ,item.url,item.src));
        }
        ltlLink.Text = sb.ToString();
    }

    private void Loadparty()
    {
        var list = new BllPartyinfor().GetList(c => true , true, c => c.time,1,7);
        StringBuilder sb = new StringBuilder();
        foreach (var item in list)
        {
            string name = item.name;
            sb.Append(string.Format(@"<li>
                                    <a href='partyc.aspx?id={0}' target='_blank' title='{1}'>{2}</a><span>{3}</span></li>"
                , item.id,name, name.Length > 14 ? name.Substring(0, 14) + "..." : name, item.time.ToString().Substring(0,10)));
        }
        ltlParty.Text = sb.ToString();
    }

    private void Loadgroup()
    {
        throw new NotImplementedException();
    }

    private void Loadnews()
    {
        BllNews bll = new BllNews();
        var list = bll.GetList(c => true, true, c => c.time, 1, 5);
        StringBuilder sb = new StringBuilder();
        foreach (var item in list)
        {
            string name = item.name;
            sb.Append(string.Format(@"<li>·<a href='newsc.aspx?id={0}' target='_blank' title='{1}'> <span>{2}</span><span
                        class='right'>{3}</span></a></li>"
                , item.id, name, name.Length > 14 ? name.Substring(0, 14) + "..." : name,item.time.ToShortDateString()));
        }

        var list1 = bll.GetList(c =>c.type==2, true, c => c.time, 1, 6);
        StringBuilder sb1 = new StringBuilder();
        foreach (var item in list1)
        {
            string name = item.name;
            sb1.Append(string.Format(@"<li><a href='newsc.aspx?id={0}' target='_blank' title='{1}'> <span>{2}</span><span
                        class='right'>{3}</span></a></li>"
                , item.id, name, name.Length > 14 ? name.Substring(0, 14) + "..." : name, item.time.ToShortDateString()));
        }
        var list2 = bll.GetList(c => c.type == 3, true, c => c.time, 1, 14);
        StringBuilder sb2 = new StringBuilder();
        foreach (var item in list2)
        {
            string name = item.name;
            sb2.Append(string.Format(@"<li><a href='newsc.aspx?id={0}' target='_blank' title='{1}'>{2}</a></li>"
                , item.id, name, name.Length > 15 ? name.Substring(0, 15) + "..." : name));
        }
        ltlNews.Text = sb.ToString();
        ltlNews1.Text = sb1.ToString();
        ltlNews2.Text = sb2.ToString();
    }

    private void Loadinfor()
    {
        throw new NotImplementedException(); 
    }

    private void Loadnotice()
    {
        var list = new BllNotice().GetList(c => c.show = true, true, c => c.date);
         StringBuilder sb = new StringBuilder();
        foreach (var item in list)
        { 
            string name=item.name;
            sb.Append(string.Format(@"<li><a href='notice.aspx?id={0}' target='_blank' title='{1}'>
                            {2}</a></li>", item.id, name, name.Length > 23 ? name.Substring(0, 23) + "..." : name));
        }
        ltlNotice.Text = sb.ToString();
    }

    private void Loadservices()
    {
        BllServices bll = new BllServices();
        StringBuilder sb = new StringBuilder();
        List<string> pic = new List<string>();
        pic.Add("img/index/审计.jpg");
        pic.Add("img/index/资产评估.jpg");
        pic.Add("img/index/造价机构.jpg");
        pic.Add("img/index/项目管理.jpg");
        var list = bll.GetList(c => true, true, c => c.sort, 1, 4);
        int count = 0;
        foreach (var item in list)
        {
            sb.Append(string.Format(@"<div>
                    <img class='left' src='{0}' alt='pic' />
                    <ul class='isul'>
                        <li class='ilit1'>{1}</li>
                        <li class='ilit2'>{2}</li>
                    </ul>
                </div>", pic[count], item.name, item.remark));
            count++;
        }
        ltlSer.Text = sb.ToString();
    }
}